package com.eshop.modules.activity.service.impl;

import org.slf4j.LoggerFactory;
import java.lang.invoke.SerializedLambda;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.eshop.modules.activity.domain.StoreBargainUser;
import java.io.Serializable;
import com.eshop.modules.user.domain.ShopUser;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Collections;
import cn.hutool.core.util.ObjectUtil;
import com.eshop.modules.activity.vo.StoreBargainUserHelpQueryVo;
import java.util.List;
import com.eshop.modules.user.service.UserService;
import com.eshop.modules.activity.service.StoreBargainUserService;
import org.springframework.beans.factory.annotation.Autowired;
import com.eshop.dozer.service.IGenerator;
import org.slf4j.Logger;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.activity.service.StoreBargainUserHelpService;
import com.eshop.modules.activity.domain.StoreBargainUserHelp;
import com.eshop.modules.activity.service.mapper.StoreBargainUserHelpMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(rollbackFor = { Exception.class })
public class StoreBargainUserHelpServiceImpl extends BaseServiceImpl<StoreBargainUserHelpMapper, StoreBargainUserHelp> implements StoreBargainUserHelpService
{
    private static final Logger log;
    @Autowired
    private IGenerator generator;
    @Autowired
    private StoreBargainUserHelpMapper storeBargainUserHelpMapper;
    @Autowired
    private StoreBargainUserService storeBargainUserService;
    @Autowired
    private UserService userService;
    
    public List<StoreBargainUserHelpQueryVo> getList(final Long bargainId, final Long bargainUserUid, final int page, final int limit) {
        final StoreBargainUser storeBargainUser = this.storeBargainUserService.getBargainUserInfo(bargainId, bargainUserUid);
        if (ObjectUtil.isNull(storeBargainUser)) {
            return Collections.emptyList();
        }
        final Page<StoreBargainUserHelp> pageModel = (Page<StoreBargainUserHelp>)new Page((long)page, (long)limit);
        final LambdaQueryWrapper<StoreBargainUserHelp> wrapper = (LambdaQueryWrapper<StoreBargainUserHelp>)new LambdaQueryWrapper();
        (wrapper.eq(StoreBargainUserHelp::getBargainUserId, storeBargainUser.getId())).orderByDesc(StoreBargainUserHelp::getId);
        final List<StoreBargainUserHelpQueryVo> storeBargainUserHelpQueryVos = (List<StoreBargainUserHelpQueryVo>)this.generator.convert(((Page)this.storeBargainUserHelpMapper.selectPage((IPage)pageModel, (Wrapper)wrapper)).getRecords(), (Class)StoreBargainUserHelpQueryVo.class);
        storeBargainUserHelpQueryVos.forEach(item -> {
           ShopUser shopUser = (ShopUser)this.userService.getById((Serializable)item.getUid());
            item.setAvatar(shopUser.getAvatar());
            item.setNickname(shopUser.getNickname());
            return;
        });
        return storeBargainUserHelpQueryVos;
    }
    
    public int getBargainUserHelpPeopleCount(final Long bargainId, final Long bargainUserUid) {
        return ((this.lambdaQuery().eq(StoreBargainUserHelp::getBargainUserId, bargainUserUid)).eq(StoreBargainUserHelp::getBargainId, bargainId)).count();
    }
    
    static {
        log = LoggerFactory.getLogger((Class)StoreBargainUserHelpServiceImpl.class);
    }
}
